import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../views/Login.vue";
import home from "@/components/home";
import users from "@/components/users";
import roles from "@/components/roles";
import rights from "@/components/rights";
import goods from "@/components/goods";
import params from "@/components/params";
import categories from "@/components/categories";
import orders from "@/components/orders";
import reports from "@/components/reports"
Vue.use(VueRouter)
const routes = [
  { path:'/' , redirect:'/login'},
  { path:'/login', component: Login},
  { path: '/home', component: home,
      children:[
      { path: '/users', component: users, meta: { bread: ["用户管理","用户列表"]}},
      { path: '/roles', component: roles, meta: { bread: ["权限管理","角色列表"]}},
      { path: '/rights',component: rights,meta: { bread: ["权限管理","权限列表"]}},
      { path: '/goods', component: goods ,meta: { bread: ["商品管理","商品列表"]}},
      { path: '/params', component: params,meta: { bread: ["商品管理","分类参数"]}},
      { path: '/categories',component: categories,meta: { bread: ["商品管理","商品分类"]}},
      { path: '/orders',component: orders,meta:{ bread: ["订单管理","订单列表"]}},
      { path: '/reports',component: reports,meta: { bread: ["数据统计","数据报表"]}}]
  }
]
const router = new VueRouter({
  routes
})
// 路由导航守卫
router.beforeEach((to, from,next) =>{
  //to 将要访问的路径
  //from从哪里来
  //next（）放行 next（‘’）强制跳转
  if (to.path ==='/login') return next()
  const tokenStr=window.sessionStorage.getItem('token')
  if (!tokenStr) return  next('/login')
  next()
})
export default router
